﻿@{
    ViewData["Title"] = "修改供应商";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">供应商编码</label>

                <div class="layui-input-block">
                    <input type="text" name="VendorCode" id="VendorCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
                <input type="checkbox" checked lay-skin="switch" lay-filter="switchTest" title="自动生成">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">供应商名称</label>
                <div class="layui-input-block">
                    <input type="text" name="VendorName" id="VendorName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">供应商简称</label>
                    <div class="layui-input-block">
                        <input type="text" name="VendorNick" id="VendorNick" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">供应商等级</label>
                        <div class="layui-input-block">
                            <select name="VendorLevel" id="VendorLevel" lay-filter="aihao" lay-verify="required">
                                <option value=""></option>
                                <option value="A">优质供应商</option>
                                <option value="B">正常</option>
                                <option value="C">重点关注</option>
                                <option value="D">劣质供应商</option>
                                <option value="E">黑名单</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">供应商评分</label>
                    <div class="layui-input-block">
                        <input type="text" name="VendorScore" id="VendorScore" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">供应商电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="Tel" id="Tel" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="demo2">修改</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>

    </form>

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use(['form'], function () {
            var layer = layui.layer;
            var form = layui.form;
            
            function generateVendorCode() {
                $("#VendorCode").val(parent.VendorCode);
                $("#VendorName").val(parent.VendorName);
                $("#VendorNick").val(parent.VendorNick);
                $("#VendorLevel").val(parent.VendorLevel);
                $("#VendorScore").val(parent.VendorScore);
                $("#Tel").val(parent.Tel);
            }
            generateVendorCode()
            

            // 表单提交事件
            form.on('submit(demo2)', function (data) {
                var field = data.field; // 获取表单字段值
                console.log(field);
                var UpdateDto = {
                    //获取表单
                    VendorCode: field.VendorCode,
                    VendorName: field.VendorName,
                    VendorNick: field.VendorNick,
                    VendorLevel: field.VendorLevel,
                    VendorScore: field.VendorScore,
                    Tel: field.Tel,

                    //数据库值
                    Id: parent.Id,
                    VendorEn: parent.VendorEn,
                    VendorDesc: parent.VendorDesc,
                    VendorLogo: parent.VendorLogo,
                    Address: parent.Address,
                    Website: parent.Website,
                    Email: parent.Email,
                    Contact1: parent.Contact1,
                    Contact1Tel: parent.Contact1Tel,
                    Contact1Email: parent.Contact1Email,
                    Contact2: parent.Contact2,
                    Contact2Tel: parent.Contact2Tel,
                    Contact2Email: parent.Contact2Email,
                    CreditCode: parent.CreditCode,
                    Remark: parent.Remark,
                    CreateBy: parent.CreateBy,
                    CreateTime: parent.CreateTime,
                }
                $.ajax({
                    url: "/Meng/UpdateMdVendor",
                    type: "get",
                    async: true,
                    data: UpdateDto,
                    contentType: "application/json",
                    success: res => {
                        if (res == 1) {
                            alert("修改成功")
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                        else {
                            console.log(res.code)
                            alert("修改失败")
                        }
                    }
                });
                console.log("1")
                return false; // 阻止默认 form 跳转
            });
        });

    </script>

</body>
</html>